<!--
 * @Author: wangzm
 * @Date: 2020-03-16 15:35:10
 * @LastEditors: wjk
 * @LastEditTime: 2020-09-01 11:29:46
 * @Description: 引导页组件
 -->
<template>
  <view v-if="show" class="guide-box">
    <view class="guide-mask"></view>
    <view class="guide-content" :style="position" @click="close">
      <b-image class-name="goods-pic" :src="guidePic" :is-asset="isAsset" mode="widthFix" />
    </view>
  </view>
</template>
<script>
import { mapState } from 'vuex'
export default {
  props: {
    position: { // 引导页图片位置, css
      type: String,
      default: ''
    },
    guidePic: { // 引导页图片地址
      type: String,
      default: ''
    },
    isAsset: { // 网络图
      type: Boolean,
      default: true
    },
    byUser: { // 根据用户展示
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      show: false,
      storageObj: {},
      storageName: ''
    }
  },
  computed: {
    ...mapState([
      'userInfo'
    ])
  },
  created() {
    this.storageObj = uni.getStorageSync('storageGuide') || {}
    if (this.userInfo && this.byUser) {
      this.storageName = this.userInfo.mobile + this.guidePic
    } else {
      this.storageName = this.guidePic
    }
    if (!this.storageObj[this.storageName]) {
      this.show = true
    }
  },
  methods: {
    close() {
      this.storageObj[this.storageName] = true
      uni.setStorageSync('storageGuide', this.storageObj)
      this.show = false
    }
  }
}
</script>
 <style lang="scss">
 .guide-box{
   box-sizing: content-box;
   padding-bottom: constant(safe-area-inset-bottom);
   padding-bottom: env(safe-area-inset-bottom);
   left: 0;
   right: 0;
   bottom: 0;
   top: 0;
   position: fixed;
   z-index: 2;
   display: flex;
   justify-content: center;
   .guide-mask{
     background-color: rgba(0,0,0,0.6);
     position: absolute;
     left: 0;
     top: 0;
     bottom: 0;
     right: 0;
   }
   .guide-content{
     position: relative;
     width: 100%;
   }
 }
 </style>
